# Create your models here.
from django.db import models
from django.contrib.auth.models import AbstractUser
from django.utils import timezone
from tinymce.models import HTMLField


class TUser(AbstractUser):  # 用户模型
    status = (
        ('male', '男'),
        ('female', '女')
    )
    username = models.EmailField(unique=True)
    password = models.CharField(max_length=128)
    sex = models.CharField(max_length=6, choices=status, default='male')

    class Meta:
        db_table = 'tuser'


class TNewsType(models.Model):  # 新闻类型模型
    typename = models.CharField(max_length=128)

    class Meta:
        db_table = 'tnewstype'


class TChart(models.Model):  # 新闻类型模型
    match_id = models.CharField(max_length=256)
    state = models.CharField(max_length=256)
    chart_id = models.CharField(max_length=256)
    path = models.CharField(max_length=256)

    class Meta:
        db_table = 'tchart'


class TNews(models.Model):  # 新闻模型
    title = models.CharField(max_length=256, blank=True, null=True)
    create_time = models.DateTimeField(default=timezone.now)
    input_news_id = models.CharField(max_length=30, blank=True, null=True)
    press_release = HTMLField()
    news_type = models.ForeignKey(TNewsType, models.CASCADE, related_name='type_news')
    user = models.ForeignKey(TUser, models.CASCADE, related_name='user_news')

    class Meta:
        db_table = 'tnews'


class TImage(models.Model):  # 图片模型
    image_path = models.CharField(max_length=512, blank=True, null=True)
    news = models.ForeignKey(TNews, models.CASCADE)

    class Meta:
        db_table = 'timage'


class TClip(models.Model):  # 视频剪辑模型
    clip_path = models.CharField(max_length=512, blank=True, null=True)
    news = models.ForeignKey(TNews, models.CASCADE)

    class Meta:
        db_table = 'tclip'


class TSource(models.Model):  # 上传素材模型
    vedio_path = models.CharField(max_length=512, blank=True, null=True)
    text = models.CharField(max_length=512, blank=True, null=True)
    news = models.OneToOneField(TNews, on_delete=models.CASCADE)

    class Meta:
        db_table = 'tsource'

